<template>
  <div class="newDetails">
    <div class="newListHeader">
      <top :title="title">
        <router-link to="/home/newList" slot="back">
          <!--slot插槽-->
          <mt-button icon="back">返回</mt-button>
        </router-link>
      </top>
    </div>

    <div class="pageContainer">
      <h2>{{ news.title }}</h2>
      <div class="content" v-html="content"></div>
    </div>
  </div>
</template>

<script>
import Top from "../components/top";
export default {
  name: "NewDetails",
  components: {
    Top,
  },
  data() {
    return {
      title: "新闻详情",
      news: "",
      content: "",
    };
  },
  created() {
    var newsId = this.$route.params.newsId;
    this.$http.get("/news/detail?newsId=" + newsId).then((res) => {
      this.news = res.data.data;
      let rawContent = this.news.content;
      //console.log(this.news);
      rawContent = rawContent.replace(/&lt;/g, "<");
      rawContent = rawContent.replace(/&gt;/g, ">");
      rawContent = rawContent.replace(/&quot;/g, '"');
      rawContent = rawContent.replace(/&#x2F;/g, "/");
      rawContent = rawContent.replace(/&amp;ldquo;/g, "“");
      rawContent = rawContent.replace(/&amp;rdquo;/g, "”");
      this.content = rawContent;
    });
  },
};
</script>

<style lang="scss">
.newDetails {
  height: calc(100% - 55px);
  text-align: left;
}
.pageContainer {
  height: calc(100% - 40px);
  padding: 15px;
  overflow-y: scroll;
  overflow-x: hidden;
}
.content{
  overflow: hidden;
}
.content div img {
  width: 100%;
  max-height: 200px;
  object-fit: cover;
}
</style>